package com.cyw.search.controller;

import cn.easyes.core.biz.PageInfo;
import com.cyw.common.core.controller.BaseController;
import com.cyw.common.core.domain.R;
import com.cyw.search.entity.monents.Moments;
import com.cyw.search.service.SearchMomentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @Author: Chenyw
 * @Date: 2022/11/02/17:42
 */
@Api(value = "朋友圈文档搜索接口", tags = {"朋友圈文档搜索接口"})
@RestController
@RequestMapping("/search/moments")
public class EsMomentsController extends BaseController {

    @Resource
    private SearchMomentsService searchMomentsService;

    @ApiOperation("发布/编辑圈子")
    @PostMapping("publishMoments")
    public R publishMoments(@ApiParam("经纬度字符串->(纬,经)") @RequestParam("geoPoint") String geoPoint,
                                               @ApiParam("内容") @RequestParam("content") String content,
                                               @ApiParam("图片") @RequestPart("files") MultipartFile[] multipartFiles) {
        return searchMomentsService.publishMoments(geoPoint,content,multipartFiles);
    }

    @ApiOperation("分页输入搜索圈子")
    @GetMapping("searchMomentsByContent")
    public R<PageInfo<Moments>> searchMomentsByContent(@ApiParam("输入搜索内容") @RequestParam("searchContent") String searchContent,
                                                  @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchMomentsService.searchMomentsByContent(searchContent,pageNum,pageSize));
    }

    @ApiOperation("分页查看我附近的圈子")
    @GetMapping("searchNearMoments")
    public R<PageInfo<Moments>> searchNearMoments(@ApiParam("经纬度字符串->(纬,经)") @RequestParam("geoPoint") String geoPoint,
                                                  @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchMomentsService.searchNearMoments(geoPoint,pageNum,pageSize));
    }

    @ApiOperation("分页查看所有圈子")
    @GetMapping("searchAllMoments")
    public R<PageInfo<Moments>> searchAllMoments( @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchMomentsService.searchAllMoments(pageNum,pageSize));
    }

    @ApiOperation("分页查看我关注的圈子")
    @GetMapping("searchFollowMoments")
    public R<PageInfo<Moments>> searchFollowMoments( @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchMomentsService.searchFollowMoments(pageNum,pageSize));
    }

    @ApiOperation("分页查看我发布的所有圈子")
    @GetMapping("searchMyMoments")
    public R<PageInfo<Moments>> searchMyMoments( @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                  @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize){
        return R.ok(searchMomentsService.searchMyMoments(pageNum,pageSize));
    }

    @ApiOperation("根据userId获取此用户下的圈子")
    @GetMapping("searchMomentsByUserId")
    public R<PageInfo<Moments>> searchMomentsByUserId(@ApiParam("页码") @RequestParam("userId") Long userId,
                                                      @ApiParam("页码") @RequestParam("pageNum") Integer pageNum,
                                                      @ApiParam("每页显示数") @RequestParam("pageSize") Integer pageSize) {
        return R.ok(searchMomentsService.searchMomentsByUserId(userId,pageNum, pageSize));
    }

    @ApiOperation("删除圈子")
    @DeleteMapping("deleteMoments/{momentsId}")
    public R deleteMoments(@PathVariable("momentsId") String momentsId){
        return R.ok(searchMomentsService.deleteMoments(momentsId));
    }
}
